//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    days:'20',
    totalcount:'30',
    authuserInfor:{},
    index: 0,
    name:'人生若只如初见',
    selected:true,
    selected1:false,
    selected2:false,
    signstate:false,
    iconcolor:['gray'],
    circlelist:[
      {id:'1',
      circletype:'circle',
      listtype:'mastery',
      userimg:'/static/img/2.jpg',
      username:'抽抽',
      addtime:'2019/09/23',
      circletitle:'糖醋排骨',
      continuityday:'连续3天',
      circledes:' 最好要寸排，骨头越细的那种越好，说明猪岁数比较小，肉嫩，而且小骨头不压分量;2.处理好排骨，买小寸排最好，这次我用的',
      circleimg:[{imgurl:'https://f11.baidu.com/it/u=2646093511,2820815036&fm=72'},{imgurl:'https://f10.baidu.com/it/u=1856966395,724479572&fm=72'}],
      viewnum:2,
      zan:1,
      like:false,
      zanstate:false,
      caistate:false,
      cai:2},
       {id:'2',
      circletype:'circle',
      listtype:'recommend',
      userimg:'/static/img/2.jpg',
      username:'抽抽',
      addtime:'2019/09/23',
      circletitle:'宫保鸡丁',
      continuityday:'连续3天',
      circledes:'最好要寸排，骨头越细的那种越好，说明猪岁数比较小，肉嫩，而且小骨头不压分量;2.处理好排骨，买小寸排最好，这次我用的',
      circleimg:[{imgurl:'https://f10.baidu.com/it/u=3250680277,1257668285&fm=72'}],
      viewnum:2,
      zan:1,
      like:false,
      zanstate:false,
      caistate:false,
      cai:2},
      {id:'3',
      circletype:'circle',
      listtype:'event',
      userimg:'/static/img/2.jpg',
      username:'抽抽',
      addtime:'2019/09/23',
      circletitle:'宫保鸡丁',
      continuityday:'连续3天',
      circledes:'最好要寸排，骨头越细的那种越好，说明猪岁数比较小，肉嫩，而且小骨头不压分量;2.处理好排骨，买小寸排最好，这次我用的',
      circleimg:[{imgurl:'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=587919929,3987387314&fm=23&gp=0.jpg'},{imgurl:'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=801875224,3562248532&fm=23&gp=0.jpg'},{imgurl:'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1202455018,1076925148&fm=23&gp=0.jpg'},{imgurl:'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3240246909,941684714&fm=23&gp=0.jpg'},{imgurl:'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2242758784,317689828&fm=23&gp=0.jpg'},{imgurl:'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1022363636,719495928&fm=23&gp=0.jpg'}],
      viewnum:2,
      zan:1,
      like:false,
      zanstate:false,
      caistate:false,
      cai:2},
      {id:'4',
      circletype:'sign',
      listtype:'event',
      userimg:'/static/img/2.jpg',
      username:'抽抽',
      addtime:'2019/09/23',
      signtxt:'完成05月12日签到打卡，连续第1天',
      viewnum:2,
      zan:1,
      like:false,
      zanstate:false,
      caistate:false,
      cai:2}
      ]
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs',
      
    })
  },
  //签到事件
  signin:function(){
    this.setData({
            signstate:true
        })
  },
  //tab选择事件
   selected:function(e){
        this.setData({
            selected:true,
            selected1:false,
            selected2:false
        })
    },
    selected1:function(e){
        this.setData({
            selected:false,
            selected1:true,
            selected2:false
        })
    },
    selected2:function(e){
        this.setData({
            selected:false,
            selected1:false,
            selected2:true
        })
    },
   bindPickerChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },
  collection:function(e){
    let currentIndex =e.currentTarget.dataset.id-1
    let state=this.data.circlelist[currentIndex].like
    if(state===false){
      this.setData({
        ['circlelist['+currentIndex+'].like']:true
      })
    }else{
      this.setData({
        ['circlelist['+currentIndex+'].like']:false
      })
    }
    
  },
  zan:function(e){
    let currentIndex =e.currentTarget.dataset.id-1
    let state=this.data.circlelist[currentIndex].zanstate
    let zannum=this.data.circlelist[currentIndex].zan
    if(state===false){
    this.setData({
        ['circlelist['+currentIndex+'].zanstate']:true,
        ['circlelist['+currentIndex+'].zan']:zannum+1
    })
    }else{
      this.setData({
        ['circlelist['+currentIndex+'].zanstate']:false,
        ['circlelist['+currentIndex+'].zan']:zannum-1
      })
      }
  },
  nolike:function(e){
    let currentindex =e.currentTarget.dataset.id
    console.log(currentindex)
    wx.navigateTo({
      url: '../comment/comment?id='+currentindex
    })
  },
  previewimg:function(e){
    let currentIndex =e.currentTarget.dataset.id-1
    let circleimg=this.data.circlelist[currentIndex].circleimg
    let imgurls=[]
    for(let i=0;i<circleimg.length;i++){
      let url=circleimg[i].imgurl
      imgurls.push(url)
    }
    
      wx.previewImage({
        current: '', // 当前显示图片的http链接
        urls: imgurls// 需要预览的图片http链接列表
      })
  },
  onLoad: function () {
    console.log('onLoad')
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
    })
    app.getTestData(function(res){
      that.setData({
        motto:res.data.title,
        author:res.data.nickname
      })
    })

    //  wx.request( {  
    //     url: "http://rapapi.org/mockjsdata/18633/circlelist",  
    //     success: function(res) {  
    //       that.setData( {  
    //         circle_list:res.data  
    //       })  
    //     }  
    //   })  
}
})